package com.house365.core.thirdpart.auth.dto;

import android.os.Bundle;
import android.text.TextUtils;

/**
 * @author py
 * @date 2012-11-5
 * @comment
 */
public class AccessToken {
	public AccessToken() {
	}

	public static final String TOKEN = "access_token";
	public static final String EXPIRES = "expires_in";
	public static final String OPENID = "openid";
	public static final String UID = "uid";
	private String token;
	private String tokenSecret;
	private long expiresIn = 0;

	// qq微博用到
	private String openid;
	// sina
	private String uid;

	public String getTokenSecret() {
		return tokenSecret;
	}

	public void setTokenSecret(String tokenSecret) {
		this.tokenSecret = tokenSecret;
	}

	public AccessToken(Bundle values) {
		token = values.getString(TOKEN);
		setExpiresIn(values.getString(EXPIRES));
	}

	public AccessToken(String token, String tokenSecret) {
		super();
		this.token = token;
		this.tokenSecret = tokenSecret;
	}

	public AccessToken(String token, String tokenSecret, String expiresIn) {
		this.token = token;
		this.tokenSecret = tokenSecret;
		if (expiresIn != null && !expiresIn.equals("0")) {
			setExpiresIn(System.currentTimeMillis() + Long.parseLong(expiresIn)
					* 1000);
		}
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public long getExpiresIn() {
		return expiresIn;
	}

	public void setExpiresIn(long expiresIn) {
		this.expiresIn = expiresIn;
	}

	public void setExpiresIn(String expiresIn) {
		if (expiresIn != null && !expiresIn.equals("0")) {
			setExpiresIn(System.currentTimeMillis() + Long.parseLong(expiresIn)
					* 1000);
		}
	}

	public boolean isSessionValid() {
		return (!TextUtils.isEmpty(token) && (getExpiresIn() == 0 || (System
				.currentTimeMillis() < getExpiresIn())));
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}
	
	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}
	

}
